<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">

<head>
  <meta charset="utf-8">
  <meta name="viewport"
    content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <title>代码生成</title>
  <link rel="stylesheet" href="/layui/css/layui.css" media="all">
<!--  <link rel="stylesheet" href="/css/admin.css" media="all">-->
  <link rel="stylesheet" href="/css/custom.css" media="all">
  <style>
    body {
      margin: 10px;
    }

    .demo-carousel {
      height: 200px;
      line-height: 200px;
      text-align: center;
    }
  </style>
</head>

<body class="layui-layout-body">

  <div id="topTabs" class="layui-tab layui-tab-card" lay-filter="generatorTab">
    <ul class="layui-tab-title">
      <li class="layui-this" lay-id="dataSource"><span class="title">数据源配置</span></li>
      <li lay-id="templates"><span class="title">模板管理</span></li>
      <li lay-id="backend"><span class="title">后台代码生成</span></li>
    </ul>
    <div class="layui-tab-content">
      <div class="layui-tab-item layui-show">
        <table class="layui-hide" id="dataSourceTable" lay-filter="dataSourceFilter"></table>
      </div>
      <div class="layui-tab-item">
        <table class="layui-hide" id="templatesTable" lay-filter="templatesFilter"></table>
      </div>
      <div class="layui-tab-item">
        <form class="searchForm layui-form">
          数据源：
          <div class="layui-inline">
            <select id="dataSource" name="dataSource"
              lay-filter="dataSource">
            </select>
          </div>
          数据库：
          <div class="layui-inline">
            <select id="tableSchema" name="tableSchema"
              lay-filter="tableSchema">
            </select>
          </div>
          表名：
          <div class="layui-inline">
            <select id="tableName" name="tableName" lay-filter="tableName">
            </select>
          </div>
          <button type="button" class="layui-btn" data-type="reload">搜索
          </button>
        </form>
    
        <table class="layui-hide" id="generatorTable" lay-filter="generatorFilter"></table>
      </div>
    </div>
  </div>

  <!-- 工具栏模板： -->
  <script type="text/html" id="dataSourceToolbar">
    <div class="layui-btn-group">
      <button type="button" class="layui-btn layui-btn-sm" lay-event="add">
        <i class="layui-icon layui-icon-add-1"></i>
      </button>
      <button type="button" class="layui-btn layui-btn-sm" lay-event="delete">
        <i class="layui-icon layui-icon-delete"></i>
      </button>
    </div>
  </script>

  <script type="text/html" id="templatesToolbar">
    <div class="layui-btn-group">
      <button type="button" class="layui-btn layui-btn-sm" lay-event="add">
        <i class="layui-icon layui-icon-add-1"></i>
      </button>
      <button type="button" class="layui-btn layui-btn-sm" lay-event="delete">
        <i class="layui-icon layui-icon-delete"></i>
      </button>
    </div>
  </script>
  
  <script type="text/html" id="backendToolbar">
    <div class="layui-btn-group">
      <button type="button" class="layui-btn layui-btn-sm" lay-event="config">
        配置
      </button>
    </div>
  </script>

  <script type="text/html" id="dataSourceBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="test">测试链接</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  </script>

  <script type="text/html" id="templatesBar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="addDbField">配置映射类型</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="addField">模板字段</a>
    <a class="layui-btn layui-btn-xs" lay-event="addFile">配置模版</a>
  </script>

  <script type="text/html" id="backendBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  </script>

  <script src="/layui/layui.all.js"></script>
  <script src="/common/js/common.js"></script>
  <script src="/assets/dataSource.js"></script>
  <script src="/assets/templates.js"></script>
  <script src="/assets/backend.js"></script>

  <script>
    layui.use('element', function () {
      var $ = layui.jquery;
      var element = layui.element;

      //获取hash来切换选项卡，假设当前地址的hash为lay-id对应的值
      var layId = location.hash.replace(/^#generatorTab=/, '');
      element.tabChange('generatorTab', layId); //假设当前地址为：http://a.com#test1=222，那么选项卡会自动切换到“发送消息”这一项

      //监听Tab切换，以改变地址hash值
      element.on('tab(generatorTab)', function () {
        location.hash = 'generatorTab=' + this.getAttribute('lay-id');
      });

      layui.use('contextMenu', function () {
        var contextMenu = layui.contextMenu;
        if (contextMenu) {  // contextMenu模块可能会不存在
          $('#topTabs>.layui-tab-title').off('contextmenu.tab').on('contextmenu.tab', 'li', function (e) {
            var layId = $(this).attr('lay-id');
            contextMenu.show([{
              icon: 'layui-icon layui-icon-refresh',
              name: '刷新当前',
              click: function () {
                element.tabChange('generatorTab', layId);
              }
            }], e.clientX, e.clientY);
            return false;
          });
        }
      });
      
    });
  </script>
</body>

</html>
